package com.huijutao.activityContent;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.huijutao.CustomView.WebViewSetting;
import com.huijutao.MyApp;
import com.huijutao.R;
import com.huijutao.beans.GroupItem;


public class GroupActivity extends ActionBarActivity {
    public static final String DATA = "data";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_group);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        //设置Up按钮
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        //获取数据
        final GroupItem groupItem = (GroupItem) getIntent().getSerializableExtra(DATA);
        ImageView img = (ImageView) findViewById(R.id.img);
        TextView txt_title = (TextView) findViewById(R.id.txt_title);
        TextView txt_price = (TextView) findViewById(R.id.txt_price);
        TextView txt_attend = (TextView) findViewById(R.id.txt_attend);
        MyApp.mImageXutils.display(img, groupItem.getImg_path());
        txt_title.setText(groupItem.getTitle());
        txt_price.setText("¥" + groupItem.getPrice());
        txt_attend.setText(groupItem.getAttend_count() + "人参加");
        //设置去购买的点击事件
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri = Uri.parse(groupItem.getGo_url());
                Intent it = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(it);
            }
        });
        //设置WebView
        WebView webView_main = (WebView) findViewById(R.id.wv);
        WebViewSetting.setWebView(webView_main);
        webView_main.loadDataWithBaseURL(null, groupItem.getMemo(), "text/html", "UTF-8", null);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            this.finish();
        }
        return super.onOptionsItemSelected(item);
    }
}
